import express from "express";
import db from "../db/db.js";

const clearFundPrincipal = express.Router();

const detailData = async (params: any) => {
    return new Promise((resolve, reject) => {
        let sql = `UPDATE asset SET principal = ?  WHERE code = ?;`;
        db.query(sql, [0, params.code], (err, results) => {
            if (err) {
                return reject(err);
            }
            resolve(results);
        });
    });
};

clearFundPrincipal.post("/deleteFund", async (req, res) => {
    try {
        const params = req.body;
        const dataRes: any = await detailData(params);
        res.send({
            code: 200,
            message: "删除持有基金信息 请求成功！",
            result: dataRes,
            // total: dataRes.length,
        });
    } catch (error) {
        console.error("Error fetching file records:", error);
        res.status(500).send({
            code: 1,
            message: "删除持有基金信息 请求失败！",
            result: null,
        });
    }
});

export default clearFundPrincipal;
